require(['loading'], function(loading) {
    //实例化vue
    var bulk = new Vue({
        el: '#bulk',
        data: {
            bulkData: [],
            noData: false,
            showLoading: false,
            apiUrl: wxUrl + '/v3.2/tbuyinginfo/list.do',
            item: {
                params:{
                    token: token,
                    userToken: userToken,
                    pageNo: 1,
                    pageSize: 20
                }
            }
        },
        ready: function(){
        	this.getIndexData();
        },
        methods: {
            getIndexData: function() {
				this.$http.get(this.apiUrl, this.item)
				.then(function(response){
					var result = JSON.parse(response.body);
					var bulkList = result.data.list;
					if(bulkList != null){
						this.bulkData = this.bulkData.concat(bulkList);
					}
					if(bulkList == null && this.item.params.pageNo == 1) {
						this.noData = true;
					}else{
						this.noData = false;
					}
				});
            },
            getMore: function(){
            	var contiueFlag = this.bulkData.length < this.item.params.pageNo * 20;
				if(contiueFlag) { // 如果没有更多数据，则不调用远程
					promptBox('没有更多数据了！');
					return;
				}
				this.item.params.pageNo++;
				this.getIndexData();
            },
			toEditBuy: function(){
				location.href="../userCenter/editBuy.html.html"
			}
        },
        directives: { // 自定义指令
            scroll: {
                bind: function(el, binding) {
                    window.addEventListener('scroll', function() {
                        if($(window).scrollTop() + $(window).height() == $(document).height()) {
                            bulk.getMore();
                        }
                    })
                }
            }
        }
    });
});

// 为可控制返回指定页面所有添加pushState
history.pushState({}, document.title, null);
pushVHistory();
window.addEventListener("popstate", function() {
	goBackVHistory();
});